<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .center1 {
      width: 100px;
      height: 100px;
      margin: 0 auto 50px;
      background: pink;
    }
    .center2 {
      position: relative;
      left: 50%;
      width: 100px;
      height: 100px;
      background: purple;
      transform: translate(-50%);
    }
  </style>
</head>
<body>
  <!-- 第一种方式实现水平居中 -->
  <div class="center1"></div>
  <!-- 第二种 -->
  <div class="center2"></div>
</body>
</html>